import requests
import json
import httpx
#import qianfan
import os
from openai import OpenAI
   

# os.environ["QIANFAN_AK"] = "a8bc3628280448d790fbb6573040eaa2"
# os.environ["QIANFAN_SK"] = "e9c76bf17ba44c379703666040c5b7c8"
# os.environ["QIANFAN_SSL_VERIFICATION_ENABLED"]="False"

def http_call():
        
    url = "https://qianfan.baidubce.com/v2/chat/completions"
    
    payload = json.dumps({
        "model": "DeepSeek-R1-Distill-Llama-8B",
        "messages": [
            {
                "role": "user",
                "content": "您好"
            }
        ],
        "disable_search": False,
        "enable_citation": False
    }, ensure_ascii=False)
    headers = {
        'Content-Type': 'application/json',
        'appid': '',
        'Authorization': 'Bearer bce-v3/ALTAK-lJ6ioN6xjLFxY2Yz2vST7/6f1b9465b2cd2e171923af5a9cb28882f8ebbfcf'
    }
    
    response = requests.request("POST", url, headers=headers, data=payload.encode("utf-8"),verify=False)
    
    print(response.text)
    
def sdk_con():
    

    client = OpenAI(
        base_url='https://qianfan.baidubce.com/v2',
        api_key='bce-v3/ALTAK-lJ6ioN6xjLFxY2Yz2vST7/6f1b9465b2cd2e171923af5a9cb28882f8ebbfcf',
        http_client=httpx.Client(verify=False)
    )
    chat_completion = client.chat.completions.create(
        model="deepseek-r1-distill-qwen-7b", 
        messages=[
        {
            "role": "user",
            "content": "您好"
        }
    ]
    )
    print(chat_completion)

def embedding_gen():
    resp = qianfan.Embedding().do(endpoint="bge_large_zh",texts=["你好"])
    print(resp.body)
    
if __name__ == '__main__':
    ## http_call()
    ## sdk_con()
    embedding_gen()
